﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace DotNetExtensions.Core
{
    public static class CustomAttributeExtensions
    {
        public static T GetCustomAttribute<T>(this Type type) where T : Attribute
        {
            var attrs = type.GetCustomAttributes(typeof(T), false);
            if (attrs != null && attrs.Length > 0) return attrs[0] as T;

            return default;
        }

        public static T GetCustomAttribute<T>(this MemberInfo memberInfo) where T : Attribute
        {
            var attrs = memberInfo.GetCustomAttributes(typeof(T), false);
            if (attrs != null && attrs.Length > 0) return attrs[0] as T;

            return default;
        }
    }
}
